package com.dba.example.gwt.client.activities;

import javax.inject.Inject;

import com.dba.example.gwt.client.beans.Company;
import com.dba.example.gwt.client.beans.MyFactory;
import com.dba.example.gwt.client.places.AccountPlace;
import com.dba.example.gwt.client.views.AccountView;
import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.web.bindery.autobean.shared.AutoBean;
import com.google.web.bindery.autobean.shared.AutoBeanCodex;

public class AccountActivity extends AbstractActivity implements
		AccountView.Presenter {
	
	MyFactory factory = GWT.create(MyFactory.class);

	AccountView view;
	
	PlaceController pc;
	
	private AccountPlace place;
	
	@Inject
	public AccountActivity(AccountView view, PlaceController pc) {
		this.view = view;
		this.pc = pc;
	}
	
	public void setPlace(AccountPlace place) {
		this.place = place;
	}

	@Override
	public void start(AcceptsOneWidget containerWidget, EventBus eventBus) {
		view.setPresenter(this);
		containerWidget.setWidget(view.asWidget());
		view.displayToken(place.getToken());
		
		String json = "{id:1,name:\"blah de blah\"}";
		
		AutoBean<Company> bean = AutoBeanCodex.decode(factory, Company.class, json);
		Window.alert(bean.as().getName() + " " + bean.as().getId());
		
		//Company company = bean.as();
		
		//Window.alert(company.getName());
	}

	public void onStop() {
	}

}
